package learningjava;

public class CalcFrame extends javax.swing.JFrame {
    
    static double result=0; //итоговое значение
    static char s;
    boolean isfinal = false; //была ли нажата кнопка "="
    boolean log = false;
    
    public CalcFrame() {
        initComponents();
    }
    
   
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ConvGroup = new javax.swing.ButtonGroup();
        finalButton = new javax.swing.JButton();
        resLabel = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        plusButton = new javax.swing.JButton();
        operLabel = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        clearButton = new javax.swing.JButton();
        minusButton1 = new javax.swing.JButton();
        sqrtButton1 = new javax.swing.JButton();
        valField = new javax.swing.JFormattedTextField();
        multipButton1 = new javax.swing.JButton();
        delButton2 = new javax.swing.JButton();
        divisButton1 = new javax.swing.JButton();
        percentButton1 = new javax.swing.JButton();
        sinButton1 = new javax.swing.JButton();
        cosButton = new javax.swing.JButton();
        negateButton = new javax.swing.JButton();
        jdecG = new javax.swing.JRadioButton();
        jhexG = new javax.swing.JRadioButton();
        jBinButton1 = new javax.swing.JRadioButton();
        AndButton = new javax.swing.JButton();
        OrButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Калькулятор");
        setName("calcFrame");
        setResizable(false);

        finalButton.setText("=");
        finalButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                finalButtonActionPerformed(evt);
            }
        });

        jLabel2.setText("Операция");

        plusButton.setText("+");
        plusButton.setToolTipText("Сложение");
        plusButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                plusButtonActionPerformed(evt);
            }
        });

        jLabel3.setText("Результат");

        jLabel4.setText("=");

        clearButton.setText("C");
        clearButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearButtonActionPerformed(evt);
            }
        });

        minusButton1.setText("-");
        minusButton1.setToolTipText("Вычитание");
        minusButton1.setMaximumSize(new java.awt.Dimension(41, 23));
        minusButton1.setMinimumSize(new java.awt.Dimension(41, 23));
        minusButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                minusButton1ActionPerformed(evt);
            }
        });

        sqrtButton1.setText("√");
        sqrtButton1.setToolTipText("Корень");
        sqrtButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sqrtButton1ActionPerformed(evt);
            }
        });

        valField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00"))));

        multipButton1.setText("*");
        multipButton1.setToolTipText("Умножение");
        multipButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                multipButton1ActionPerformed(evt);
            }
        });

        delButton2.setText("←");
        delButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                delButton2ActionPerformed(evt);
            }
        });

        divisButton1.setText("/");
        divisButton1.setToolTipText("Деление");
        divisButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                divisButton1ActionPerformed(evt);
            }
        });

        percentButton1.setText("%");
        percentButton1.setToolTipText("Процент");
        percentButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                percentButton1ActionPerformed(evt);
            }
        });

        sinButton1.setText("sin");
        sinButton1.setToolTipText("Синус");
        sinButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sinButton1ActionPerformed(evt);
            }
        });

        cosButton.setText("cos");
        cosButton.setToolTipText("Косинус");
        cosButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cosButtonActionPerformed(evt);
            }
        });

        negateButton.setText("(±)");
        negateButton.setToolTipText("Смена знака");
        negateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                negateButtonActionPerformed(evt);
            }
        });

        ConvGroup.add(jdecG);
        jdecG.setSelected(true);
        jdecG.setText("Десятичная");
        jdecG.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jdecGActionPerformed(evt);
            }
        });

        ConvGroup.add(jhexG);
        jhexG.setText("Шестнадцетеричная");
        jhexG.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jhexGActionPerformed(evt);
            }
        });

        ConvGroup.add(jBinButton1);
        jBinButton1.setText("Двоичная");
        jBinButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBinButton1ActionPerformed(evt);
            }
        });

        AndButton.setText("And");
        AndButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AndButtonActionPerformed(evt);
            }
        });

        OrButton.setText("Or");
        OrButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OrButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(operLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(14, 14, 14))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jhexG)
                            .addComponent(valField, javax.swing.GroupLayout.PREFERRED_SIZE, 303, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addComponent(minusButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(divisButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(percentButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(plusButton, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
                                            .addComponent(finalButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addGap(14, 14, 14)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(multipButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addComponent(sqrtButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(clearButton, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addComponent(delButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
                                .addGap(27, 27, 27)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(cosButton, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)
                                    .addComponent(sinButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(negateButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(OrButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(AndButton, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(resLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 286, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jdecG)
                            .addComponent(jBinButton1))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(valField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(operLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(resLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(finalButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 37, Short.MAX_VALUE)
                        .addComponent(clearButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(delButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(negateButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                        .addComponent(plusButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(multipButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(sqrtButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(AndButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(sinButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(minusButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(divisButton1)
                    .addComponent(percentButton1)
                    .addComponent(cosButton)
                    .addComponent(OrButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addComponent(jdecG)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBinButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jhexG)
                .addGap(29, 29, 29))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    Double matOper(char ss, Double res, Double i)
    {
      
        try{
            switch (ss )
                {
                 case '-' : res-=i;break;
                 case '+' : res+=i;break;
                 case '*' : res*=i;break;
                 case '/' : res/=i;break;
                 case '%' : res*=(i*0.01) ;break;  
                 case '&' : res=Double.valueOf(res.intValue() & i.intValue());break; 
                 case '|' : res=Double.valueOf(res.intValue() | i.intValue());break;     
                   
                
                 }
            }
        catch(Exception e){System.out.println(e);}
    return res;
    }
    
    void clearall()
    {
         valField.setText("");
         result=0;
         s=' ';
         clearparty(true);
    }
    
    void clearparty(boolean bt)
    {
        if(bt)
         {
          operLabel.setText("");
          resLabel.setText("");
          isfinal=false; 
         } 
        
     }
    Double toDouble(String s)
    {
        return Double.parseDouble(s.replaceAll(",","."));
              
    }
    
    private void finalButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_finalButtonActionPerformed
      try
      {
         if (isfinal)
             clearall();
         
        
         if (!valField.getText().isEmpty()) //проверка на то, не пустое ли поле
          { 
             if(!log)
              {
               result=matOper(s,result,toDouble(valField.getText()));
               operLabel.setText(operLabel.getText()+s+valField.getText());
              }  else
             { result=matOper(s,result,toDouble(valField.getText()));
               operLabel.setText(operLabel.getText()+s+String.valueOf(toDouble(valField.getText()).intValue()));
             } 
         }
             
             
        valField.setText("");
         if(!log)
         {
         resLabel.setText(Double.toString(result));
         } else
            {
         
           resLabel.setText(String.valueOf(toDouble(Double.toString(result)).intValue()));
         //resLabel.setText(String.valueOf(((int)result)));
            }
         isfinal=true;
         result=0;
       
      }
      catch (Exception e){System.out.println(e);}
      
        
    }//GEN-LAST:event_finalButtonActionPerformed
       
    
    private void plusButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_plusButtonActionPerformed
       try
       {
        if (!valField.getText().isEmpty()) //проверка на то, не пустое ли поле
        {
            clearparty(isfinal);
            Double i1=toDouble(valField.getText());
           
            if (operLabel.getText().isEmpty())
               {
                operLabel.setText(valField.getText()); //если это только первая цифра, то знак перед ней не ставим
                result=i1;                      
               }
            else
               {
                operLabel.setText(operLabel.getText()+s+valField.getText());
                result=matOper(s,result,i1);
               }
            valField.setText("");
            s='+';
        }
       }
       catch (Exception e){System.out.println(e);}
    }//GEN-LAST:event_plusButtonActionPerformed

    private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButtonActionPerformed
        clearall();
    }//GEN-LAST:event_clearButtonActionPerformed

    private void minusButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_minusButton1ActionPerformed
       
       try
         {
           if (!valField.getText().isEmpty()) //проверка на то, не пустое ли поле
           {
           clearparty(isfinal);    
           Double i1=toDouble(valField.getText());
            
            if (operLabel.getText().isEmpty())
              {
                operLabel.setText(valField.getText()); //если это только первая цифра, то знак перед ней не ставим
                result=i1;
              }
            else
              {
               operLabel.setText(operLabel.getText()+s+valField.getText());
               result=matOper(s,result,i1);
              }
           }
            valField.setText("");
            s='-';
         } 
       catch (Exception e){System.out.println(e);}
    }//GEN-LAST:event_minusButton1ActionPerformed

    private void sqrtButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sqrtButton1ActionPerformed
         try
           {
            if (!valField.getText().isEmpty())
            { 
                Double i1=toDouble(valField.getText());
                valField.setText(Double.toString(Math.sqrt(i1))); 
            }
           /*   clearparty(isfinal);  
              Double i1=toDouble(valField.getText());
                 
             if(operLabel.getText().isEmpty())
                 {
                result=Math.sqrt(i1);
                               
                 }
                        
           valField.setText(Double.toString(Math.sqrt(i1)));     
            }      
          */ } 
         catch (Exception e){System.out.println(e);}
        
    }//GEN-LAST:event_sqrtButton1ActionPerformed

    private void multipButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multipButton1ActionPerformed
      
        try
          {
            if(!valField.getText().isEmpty())
            {  
              clearparty(isfinal);  
              Double i1=toDouble(valField.getText());
        
              if(operLabel.getText().isEmpty())
               {   
                result=i1;
                operLabel.setText(valField.getText());
               }
              else
               {
                operLabel.setText(operLabel.getText()+s+Double.toString(i1));
                result=matOper(s,result,i1);
               }
            }
            valField.setText("");
            s='*';
          }
        catch(Exception e){System.out.println(e);}
            
    }//GEN-LAST:event_multipButton1ActionPerformed

    private void delButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delButton2ActionPerformed
        
        try
          {
            if (!valField.getText().isEmpty())
            { 
             String s1=valField.getText();
             String s2=s1.substring(0,s1.length()-1);
             valField.setText(s2);
            }       
          }
        catch(Exception e){System.out.println(e);}
    }//GEN-LAST:event_delButton2ActionPerformed

    private void divisButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_divisButton1ActionPerformed
         try
           {
             if(!valField.getText().isEmpty())
               {
                clearparty(isfinal);   
                Double i1=toDouble(valField.getText());
        
                 if(operLabel.getText().isEmpty())
                  {   
                    result=i1;
                    operLabel.setText(valField.getText());
                   }
                  else
                   {
                    operLabel.setText(operLabel.getText()+s+Double.toString(i1));
                    result=matOper(s,result,i1);
                   }
               }          
            valField.setText("");
            s='/';
           }
         catch(Exception e){System.out.println(e);}
    }//GEN-LAST:event_divisButton1ActionPerformed

    private void percentButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_percentButton1ActionPerformed
       try
         {
            if (!valField.getText().isEmpty())
              { 
               clearparty(isfinal);
               Double i1=toDouble(valField.getText());
                 
                if(operLabel.getText().isEmpty())
                 {
                   result=i1;
                  //operLabel.setText(operLabel.getText()+s+result1);
                  operLabel.setText(valField.getText());
                  //result=matOper(s,result,result1);
                  valField.setText("");
                 }
            
              }
            s='%';
          }
        catch(Exception e){System.out.println(e);}
        
    }//GEN-LAST:event_percentButton1ActionPerformed

    private void sinButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sinButton1ActionPerformed
         try{
             if (!valField.getText().isEmpty())
              { Double i1=toDouble(valField.getText());
                 valField.setText(Double.toString(Math.sin(i1))); 
                  
              }
            /*    clearparty(isfinal);  
               Double i1=toDouble(valField.getText());
                 
             if(operLabel.getText().isEmpty())
                    {result=Math.sin(i1);
                     operLabel.setText(Double.toString(result));
                    }
                  else {        
                     operLabel.setText(operLabel.getText()+s+"sin("+i1+')');
                     result= matOper(s,result,Math.sin(i1));
                       }
               }
            valField.setText("");*/
            }catch (Exception e){System.out.println(e);}
    }//GEN-LAST:event_sinButton1ActionPerformed

    private void cosButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cosButtonActionPerformed
       try{
             if (!valField.getText().isEmpty())
              { 
                  Double i1=toDouble(valField.getText());
                 valField.setText(Double.toString(Math.cos(i1))); 
              }
             /*   clearparty(isfinal);  
               Double i1=toDouble(valField.getText());
                 
             if(operLabel.getText().isEmpty())
                    {result=Math.cos(i1);
                     operLabel.setText(Double.toString(result));
                    }
                  else {        
                     operLabel.setText(operLabel.getText()+s+"cos("+i1+')');
                     result= matOper(s,result,Math.cos(i1));
                       }
               }
            valField.setText("");*/
            }catch (Exception e){System.out.println(e); }
    }//GEN-LAST:event_cosButtonActionPerformed

    private void negateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_negateButtonActionPerformed
        try{
           
          /*   if (!valField.getText().isEmpty())
              { 
                  clearparty(isfinal);  
               Double i1=toDouble(valField.getText());
               valField.setText(Double.toString((-1)*i1)); 
              }
           */  
             if (!valField.getText().isEmpty())
              { 
                  clearparty(isfinal);  
               Double i1=toDouble(valField.getText());
               if (i1>0) i1*=-1;
               else Math.abs(i1);
               valField.setText(Double.toString(i1)); 
              }
             
             
            //valField.setText("");
            }catch (Exception e){System.out.println(e); }
    }//GEN-LAST:event_negateButtonActionPerformed

    private void jdecGActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jdecGActionPerformed
        if (!valField.getText().isEmpty())
        valField.setText(Integer.toString(toDouble(valField.getText()).intValue(),10 ));
    }//GEN-LAST:event_jdecGActionPerformed

    private void jhexGActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jhexGActionPerformed
           if (!valField.getText().isEmpty())
               valField.setText(Integer.toHexString(toDouble(valField.getText()).intValue()).toUpperCase()); 
    }//GEN-LAST:event_jhexGActionPerformed

    private void jBinButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBinButton1ActionPerformed
        if (!valField.getText().isEmpty())
       valField.setText(Integer.toBinaryString(toDouble(valField.getText()).intValue() ));
        
    }//GEN-LAST:event_jBinButton1ActionPerformed

   
    
    
    private void AndButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AndButtonActionPerformed
        try
         {
            if (!valField.getText().isEmpty())
              { 
               clearparty(isfinal);
               Double i1=toDouble(valField.getText());
                 
                if(operLabel.getText().isEmpty())
                 {
                   result=i1;
                  // operLabel.setText(str(valField.getText()));
                   operLabel.setText(String.valueOf(toDouble(valField.getText()).intValue()));
                //   operLabel.setText(str(String.valueOf(result)));
                   valField.setText("");
                   
                 }
            
              }
            s='&'; log=true;
          }
        catch(Exception e){System.out.println(e);}
    }//GEN-LAST:event_AndButtonActionPerformed

    private void OrButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OrButtonActionPerformed
        try
         {
            if (!valField.getText().isEmpty())
               { 
               clearparty(isfinal);
               Double i1=toDouble(valField.getText());
                 
                if(operLabel.getText().isEmpty())
                 {
                   result=i1;
                  // operLabel.setText(str(valField.getText()));
                   operLabel.setText(String.valueOf(toDouble(valField.getText()).intValue()));
                //   operLabel.setText(str(String.valueOf(result)));
                   valField.setText("");
                 }
            
              }
            s='|'; log=true;
          }
        catch(Exception e){System.out.println(e);}
    }//GEN-LAST:event_OrButtonActionPerformed

        
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AndButton;
    private javax.swing.ButtonGroup ConvGroup;
    private javax.swing.JButton OrButton;
    private javax.swing.JButton clearButton;
    private javax.swing.JButton cosButton;
    private javax.swing.JButton delButton2;
    private javax.swing.JButton divisButton1;
    private javax.swing.JButton finalButton;
    private javax.swing.JRadioButton jBinButton1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JRadioButton jdecG;
    private javax.swing.JRadioButton jhexG;
    private javax.swing.JButton minusButton1;
    private javax.swing.JButton multipButton1;
    private javax.swing.JButton negateButton;
    private javax.swing.JLabel operLabel;
    private javax.swing.JButton percentButton1;
    private javax.swing.JButton plusButton;
    private javax.swing.JLabel resLabel;
    private javax.swing.JButton sinButton1;
    private javax.swing.JButton sqrtButton1;
    private javax.swing.JFormattedTextField valField;
    // End of variables declaration//GEN-END:variables
}
